]> git.saurik.com Git - apple/mdnsresponder.git/blob - mDNSMacOSX/Tests/Unit Tests/DNSSEC Unit Tests/Crypto/CanonicalMethodsTest.m
mDNSResponder-1310.40.42.tar.gz
[apple/mdnsresponder.git] / mDNSMacOSX / Tests / Unit Tests / DNSSEC Unit Tests / Crypto / CanonicalMethodsTest.m
1 //
2 // ValidationMethodsTest.m
3 // Tests
4 //
5 // Copyright (c) 2020 Apple Inc. All rights reserved.
6 //
7
8 #import <XCTest/XCTest.h>
9 #include "dnssec_v2_crypto.h"
10 #include "mDNSEmbeddedAPI.h"
11 #if MDNSRESPONDER_SUPPORTS(APPLE, DNSSECv2)
12
13 @interface CanonicalMethodsTest : XCTestCase
14
15 @end
16
17 @implementation CanonicalMethodsTest
18
19 - (void)test_copy_canonical_name {
20 mDNSu8 canonical_name[MAX_DOMAIN_NAME];
21 mDNSu8 name_length;
22
23 mDNSu8 name_1[MAX_DOMAIN_NAME] = {
24 3,
25 'w', 'W', 'w',
26 5,
27 'a', 'p', 'p', 'l', 'e',
28 3,
29 'c', 'O', 'm',
30 0
31 };
32 mDNSu8 name_1_after_conversion[MAX_DOMAIN_NAME] = {
33 3,
34 'w', 'w', 'w',
35 5,
36 'a', 'p', 'p', 'l', 'e',
37 3,
38 'c', 'o', 'm',
39 0
40 };
41
42 for (unsigned long i = 15; i < sizeof(name_1); i++) {
43 name_1[i] = 255;
44 }
45
46 // basic test
47 name_length = copy_canonical_name_ut(canonical_name, name_1);
48 XCTAssertEqual(name_length, DomainNameLength((domainname *)name_1_after_conversion));
49 XCTAssert(memcmp(canonical_name, name_1_after_conversion, name_length) == 0);
50 }
51
52 - (void)test_compare_canonical_dns_name {
53 const unsigned char inputs[][256] = {
54 {7, 'e', 'x', 'a', 'm', 'p', 'l', 'e', 0}, // example.
55 {1, 'a', 7, 'e', 'x', 'a', 'm', 'p', 'l', 'e', 0}, // a.example.
56 {8, 'y', 'l', 'j', 'k', 'j', 'l', 'j', 'k', 1, 'a', 7, 'e', 'x', 'a', 'm', 'p', 'l', 'e', 0}, // yljkjljk.a.example.
57 {1, 'Z', 1, 'a', 7, 'e', 'x', 'a', 'm', 'p', 'l', 'e', 0}, // Z.a.example.
58 {4, 'z', 'A', 'B', 'C', 1, 'a', 7, 'E', 'X', 'A', 'M', 'P', 'L', 'E', 0}, // zABC.a.EXAMPLE.
59 {1, 'z', 7, 'e', 'x', 'a', 'm', 'p', 'l', 'e', 0}, // z.example.
60 {1, 1 , 1, 'z', 7, 'e', 'x', 'a', 'm', 'p', 'l', 'e', 0}, // \001.z.example.
61 {1, '*', 1, 'z', 7, 'e', 'x', 'a', 'm', 'p', 'l', 'e', 0}, // *.z.example
62 {1, 200, 1, 'z', 7, 'e', 'x', 'a', 'm', 'p', 'l', 'e', 0} // \200.z.example.
63 };
64
65 for (size_t i = 0; i < sizeof(inputs) / 256; i++) {
66 for (size_t j = 0; j < sizeof(inputs) / 256; j++) {
67 if (i < j) {
68 XCTAssertTrue(compare_canonical_dns_name(inputs[i], inputs[j]) < 0);
69 } else if (i > j) {
70 XCTAssertTrue(compare_canonical_dns_name(inputs[i], inputs[j]) > 0);
71 } else { // i == j
72 XCTAssertTrue(compare_canonical_dns_name(inputs[i], inputs[j]) == 0);
73 }
74 }
75 }
76 }
77
78 @end
79 #endif // MDNSRESPONDER_SUPPORTS(APPLE, DNSSECv2)